package predatorprey;
import java.util.*;

/**
 *
 * @author Kenneth Aamås, Vegard Hovlid, Eirik Korsnes.
 */
public abstract class Agent 
{
    protected Field field;
    protected Location location;
    // Whether the animal is alive or not.
    protected boolean alive;
    
    public Agent(Field field, Location location)
    {
        this.field = field;
        setLocation(location);
    }
    
    abstract public void act(List<Agent> newAgent);
    
    /**
     * Check whether the animal is alive or not.
     * @return true if the animal is still alive.
     */
    protected boolean isAlive()
    {
        return alive;
    }
    
    /**
     * Return the animal's location.
     * @return The animal's location.
     */
    protected Location getLocation()
    {
        return location;
    }
    
    /**
     * Place the animal at the new location in the given field.
     * @param newLocation The animal's new location.
     */
    protected void setLocation(Location newLocation)
    {
        if(location != null) 
        {
            field.clear(location);
        }
        location = newLocation;
        field.place(this, newLocation);
    }
    
    /**
     * Return the animal's field.
     * @return The animal's field.
     */
    protected Field getField()
    {
        return field;
    }
}
